<?php
/**
 * oscshop2 B2C电子商务系统
 *
 * ==========================================================================
 * @link      http://www.oscshop.cn/
 * @copyright Copyright (c) 2015-2017 oscshop.cn. 
 * @license   http://www.oscshop.cn/license.html License
 * ==========================================================================
 *
 * @author    李梓钿
 *
 */ 
namespace osc\member\controller;
use osc\common\controller\AdminBase;
use think\Db;
class CommentBackend extends AdminBase{
	
	protected function _initialize(){
		parent::_initialize();
		$this->assign('breadcrumb1','会员');
		$this->assign('breadcrumb2','商品评价');
	}
	
     public function index(){     	
		
		$query=array();
		
		$param=input('param.');
		
		if(isset($param['order'])){
			$map['Order.order_num_alias']=['eq',trim($param['order'])];	
			$query['order']=urlencode(trim($param['order']));
		}
		
		if(isset($param['status'])){
			$map['Comment.status']=['eq',$param['status']];	
			$query['status']=urlencode($param['status']);
		}
		
		if(isset($param['score'])){
			$map['Comment.score']=['eq',$param['score']];	
			$query['score']=urlencode($param['score']);
		}
		
		$map['Order.order_status_id']=['eq',config('complete_order_status_id')];	
		
		$goods_list=Db::view('Order','order_id,order_num_alias,shipping_name,order_status_id')		
			
		->view('Comment','*','Comment.order_id=Order.order_id')			
		->view('Goods','image,type,name,price','Comment.goods_id=Goods.goods_id')		
		->where($map)->paginate(config('page_num'),false,['query'=>$query]);		

		$this->assign('empty','<tr><td colspan="20">没有数据~</td></tr>');
		$this->assign('list',$goods_list);
    	return $this->fetch();
	 }
	public function set_status(){
		
		$data=input('param.');
		
		Db::name('Comment')->where('id',(int)$data['id'])->update(['status'=>$data['status']],false,true);		
		
		$comment_list=Db::name('Comment')->where(array('goods_id'=>(int)$data['goods_id'],'status'=>1))->select();
		
		$num=0;
		$score=0;
		foreach ($comment_list as $k => $v) {
			$num+=1;
			$score+=$v['score'];
		}
		
		Db::name('goods')->where('goods_id',(int)$data['goods_id'])->update(array('comment_num'=>$num,'comment_score'=>$score));
		
		storage_user_action(UID,admin('username'),config('BACKEND_USER'),'审核了评论');	
		
		$this->redirect('CommentBackend/index');
	}
}
?>